<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/7
 * Time: 18:26
 */

namespace app\admin\model\order;


use app\common\library\Auth;
use think\Model;

class Order extends Model
{

    protected $table = 'fa_order';

    protected $auth;

    public function __construct($data = [])
    {
        $this->auth = Auth::instance();
        parent::__construct($data);
    }

    public function createOrder($params = [])
    {

    }
    //当前账号是否存在未付款订单
    public function isPayExist($params = []){
        $where = [
            'uid'=>$this->auth->id,
            'type'=>$params['type'],
            'status'=>'0',
            'pay_status'=>0,
            'experts_id'=>$params['experts_id']
        ];
        return $this->where($where)->find();

    }

    //发送即将开始短信

    public function sendSms($order_id){
        file_put_contents('./test1.txt',$order_id . "\r\n",FILE_APPEND);
        return;
        $orderInfo  = self::get($order_id);
        if($orderInfo){
            $appoint_time = $orderInfo->getAttr('appoint_time');
            $sendArr = [
                'time'=>$appoint_time
            ];
            //用户手机号
            $user = db('user')->where('id',$orderInfo['uid'])->field('mobile')->find();
            $user_phone = $user['mobile'];
            $sms = new \app\common\library\ali\sms\Sms();
            $sms->setPhoneNumbers($user_phone);
            $sms->setTemplateCode('');
            $sms->setTemplateParam($sendArr);
            $sms->sendSms();
            //专家手机号
            $experts = db('user')->where('id',$orderInfo['experts_id'])->field('mobile')->find();
            $experts_phone = $experts['mobile'];
            $sms = new \app\common\library\ali\sms\Sms();
            $sms->setPhoneNumbers($experts_phone);
            $sms->setTemplateCode('');
            $sms->setTemplateParam($sendArr);
            $sms->sendSms();

        }
    }

    public function upcoming_appoint_time(){
        $id = $this->request->param('order_id');
        $order = new \app\admin\model\order\Order();
        $orderInfo = $order->get($id);
        $appoint_time = $orderInfo->getAttr('appoint_time');
        $sendArr = [
            'time'=>$appoint_time
        ];
        //用户手机号
        $user = db('user')->where('id',$orderInfo['uid'])->field('mobile')->find();
        $user_phone = $user['mobile'];
        $sms = new \app\common\library\ali\sms\Sms();
        $sms->setPhoneNumbers($user_phone);
        $sms->setTemplateCode('');
        $sms->setTemplateParam($sendArr);
        $sms->sendSms();
        //专家手机号
        $experts = db('user')->where('id',$orderInfo['experts_id'])->field('mobile')->find();
        $experts_phone = $experts['mobile'];
        $sms = new \app\common\library\ali\sms\Sms();
        $sms->setPhoneNumbers($experts_phone);
        $sms->setTemplateCode('');
        $sms->setTemplateParam($sendArr);
        $sms->sendSms();
    }

}